<?php
/* @var $this UserController */
/* @var $model User */

$this->breadcrumbs=array(
	Yii::t('app', 'Message')=>array('index'),
	Yii::t('app', 'Bulletin Board Search'),
);
$o = $paging['offset'];
$l = $paging['limit'];
?>

<div class="page-header">
	<div class="page-title"><h3><?php echo Yii::t('app', 'Image list' ) ?></h3></div>
	<div class="buttons">
		<button class="btn btn-primary" id="btn_save"><?php echo Yii::t('app', 'Save')?></button>
	</div>
</div>

<form method="post" id="edit-form">
<div class="row-fluid">
<?php for($i=0; $i<$l-1 && $i<count($images); $i++):?>
<?php $img = $images[$i] ?>
	<div class="imgobj">
		<div class="imgframe">
			<img src="<?php echo $img['url']?>" alt="" />
		</div>
		<div class="actions">
			<input type="checkbox" name="remove_images[]" value="<?php echo $img['id']?>"/>
			<a href="<?php echo $this->createUrl('delete',array('id'=>$img['id'])) ?>" class="btn btn-danger btnDelete"><?php echo Yii::t('app', 'Delete' ) ?></a>
		</div>
	</div>
<?php endfor ?>
</div>
</form>

<div class="pager">
	<ul class="yiiPager" id="yw1">
		<?php if ($o>0):?>
		<li class="previous"><a href="<?php echo $this->createUrl('index', array('offset'=>$o-$l+1)) ?>">&lt; Previous</a></li>
		<?php endif ?>
		
		<?php if (count($images)==$l):?>
		<li class="next"><a href="<?php echo $this->createUrl('index', array('offset'=>$o+$l-1)) ?>">Next &gt;</a></li>
		<?php endif ?>
	</ul>
</div>

<script>
//<![CDATA[
function setImgVertialAlign() {
	$('.imgframe img').each(function () {
		var h1 = $(this).parent().height();
		var h2 = $(this).height();
		var mt = h2<h1 ? (h1-h2)/2 : 0;
		$(this).css('margin-top', mt+'px');
	});
}

$(window).load(function () {
	setImgVertialAlign();
	$('.btnDelete').click(function (e) {
		if(confirm("<?php echo Yii::t('app', 'Are you sure you want to delete this item') ?>?")) {
			$('body > .main').addClass('loading');
			
			$.ajax({
			type: 'POST',
			url: this.href,
			success: function (data) {
				location.reload(); 			
			},
			error: function (XHR, textStatus, errorThrown) { }
		});
		}
		e.preventDefault();
	});
});
//]]>
</script>